const router = require('koa-router')()
const koaBody = require('koa-body')();
const request = require('superagent'); //不要忘记npm instal
var config=require('../config/app.config');
const co = require('co')
module.exports = router.post('/list', koaBody, co.wrap(function*(ctx) {
    console.log(ctx.request.body);
    // => POST body
    //ctx.body = JSON.stringify(ctx.request.body);
    //console.log(ctx.body)
    // 调用远程接口获取用户授权信息
    console.log(ctx.request.body)
    var res = yield request
    .post(config.host+'/api/cms/specialColumns/list')
    .send(ctx.request.body)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res);
    ctx.response.body = res.body;
    //ctx.render('index', { title: 'Nunjucks', content: 'Feifeiyu yeah!' });
  })).post('/customer', koaBody, co.wrap(function*(ctx) {
    console.log(ctx.request.body);
    // 调用远程接口获取我的订阅专栏信息
    console.log(ctx.request.body)
    var res = yield request
    .post(config.host+'/api/cms/specialColumns/customer')
    .send(ctx.request.body)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
    //ctx.render('index', { title: 'Nunjucks', content: 'Feifeiyu yeah!' });
  })).post('/contents', koaBody, co.wrap(function*(ctx) {
    console.log(ctx.request.body);
    // 调用远程接口获取我的订阅专栏信息
    console.log(ctx.request.body)
    var res = yield request
    .post(config.host+'/api/cms/specialColumns/contents')
    .send(ctx.request.body)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
    //ctx.render('index', { title: 'Nunjucks', content: 'Feifeiyu yeah!' });
  })).post('/contentDetail', koaBody, co.wrap(function*(ctx) {
    console.log(ctx.request.body);
    // 调用远程接口获取我的订阅专栏信息
    console.log(ctx.request.body)
    var res = yield request
    .post(config.host+'/api/cms/specialColumns/contentDetail')
    .send(ctx.request.body)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
    //ctx.render('index', { title: 'Nunjucks', content: 'Feifeiyu yeah!' });
  }));